package empox.pos.input;

import empox.pos.R;
import android.app.Activity;
import android.content.Intent;
import android.content.res.Configuration;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;

public class InputNumber extends Activity implements OnClickListener {
	EditText et;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);

		requestWindowFeature(Window.FEATURE_NO_TITLE);
		setContentView(R.layout.inputnum);

		et = (EditText) this.findViewById(R.id.inputnumbershow);

		for (int i = 0; i < InputButton.inputnumberarr.length; i++) {
			((Button) this.findViewById(InputButton.inputnumberarr[i]))
					.setOnClickListener(this);
		}
	}

	public void onClick(View v) {
		String value = et.getText().toString().trim();
		switch (v.getId()) {
		case R.id.numberback:
			if (value.length() > 0) {
				value = value.substring(0, value.length() - 1);
				et.setText(value);
			}
			break;
		case R.id.numberok:
			if (value.trim().length() == 0) {
				this.setResult(0);

			} else {
				this.setResult(1, new Intent().putExtra("value", value));
				this.finish();
			}

			break;
		case R.id.numberexit:
			this.setResult(0);
			this.finish();
			break;
		default:
			String s = ((Button) v).getTag().toString();
			et.append(s);
			break;
		}

	}

	@Override
	public void onConfigurationChanged(Configuration newConfig) {
		super.onConfigurationChanged(newConfig);
	}
}
